#!/usr/bin/python
# -*- coding: utf-8 -*-
import copy
import re
import sys
import os
import shutil
import traceback

import wx
# import wx.richtext as rt
import wx.dataview as dv
import wx.adv
import wx.py.images
from wx.lib.eventwatcher import cmp

from common import result_code
from utils import re_expressions, tsl_scripts, common_functions
from ui import dialog_box
from config.version import VERSION
import context

from common.log_handler import logger


class LoginFrame(wx.Frame):
    """
    登录界面
    """

    def __init__(self):
        # 创建登录窗口
        self.LoginWindow = wx.Frame(parent=None, title='（iTC）Intelligent Test Center V%s' % VERSION, size=(630, 330))
        bkg = wx.Panel(self.LoginWindow)
        self.parent = bkg
        # 标题
        textLoginTitle = wx.StaticText(bkg, -1, u"（iTC）Intelligent Test Center", style=wx.ALIGN_CENTER)
        textLoginTitle.SetForegroundColour("Black")
        textLoginTitle.SetFont(wx.Font(25, wx.ROMAN, wx.NORMAL, wx.LIGHT))

        # 登录控件
        textLoginUserName = wx.StaticText(bkg, -1, "用户名: ", style=wx.ALIGN_RIGHT)
        textLoginUserPassword = wx.StaticText(bkg, -1, "密码: ", style=wx.ALIGN_RIGHT)
        textLoginServerURL = wx.StaticText(bkg, -1, "iTC_IP: ", style=wx.ALIGN_RIGHT)
        textLoginServerPort = wx.StaticText(bkg, -1, "iTC_Port: ", style=wx.ALIGN_RIGHT)
        # 添加文本输入框
        self.inputLoginUserName = wx.TextCtrl(bkg)
        self.inputLoginUserPassword = wx.TextCtrl(bkg, style=wx.TE_PASSWORD)
        self.combox_inputLoginServerURL = wx.ComboBox(bkg, -1, value="127.0.0.1",
                                                      choices=["127.0.0.1"],
                                                      style=wx.CB_DROPDOWN)
        self.inputLoginServerPort = wx.TextCtrl(bkg)
        self.inputLoginServerPort.SetValue("9999")

        # 添加按钮，给按钮绑定事件
        ButtonLogin = wx.Button(bkg, label=u"登录")
        ButtonLogin.Bind(wx.EVT_BUTTON, self.loginTSL)
        ButtonRegister = wx.Button(bkg, label=u"注册")
        ButtonRegister.Bind(wx.EVT_BUTTON, self.LogonTSL)

        # 设置按钮的颜色
        # ButtonLogin.SetBackgroundColour("#0a74f7")
        # ButtonRegister.SetBackgroundColour("#0a74f7")

        # 提示语
        self.textTipsMessage = wx.TextCtrl(bkg, -1, u"", style=wx.TE_RIGHT | wx.TE_READONLY | wx.BORDER_NONE)
        # 组合
        hboxLoginTitle = wx.BoxSizer(wx.HORIZONTAL)
        hboxLoginTitle.Add(textLoginTitle, proportion=1, flag=wx.TOP | wx.BOTTOM, border=6)

        hboxLoginUserName = wx.BoxSizer(wx.HORIZONTAL)
        hboxLoginUserName.Add(textLoginUserName, proportion=1, flag=wx.TOP | wx.BOTTOM, border=6)
        hboxLoginUserName.Add(self.inputLoginUserName, proportion=3, flag=wx.TOP | wx.BOTTOM, border=3)

        hboxLoginUserPassword = wx.BoxSizer(wx.HORIZONTAL)
        hboxLoginUserPassword.Add(textLoginUserPassword, proportion=1, flag=wx.TOP | wx.BOTTOM, border=6)
        hboxLoginUserPassword.Add(self.inputLoginUserPassword, proportion=3, flag=wx.TOP | wx.BOTTOM, border=3)

        hboxLoginServerURL = wx.BoxSizer(wx.HORIZONTAL)
        hboxLoginServerURL.Add(textLoginServerURL, proportion=1, flag=wx.TOP | wx.BOTTOM, border=6)
        hboxLoginServerURL.Add(self.combox_inputLoginServerURL, proportion=3, flag=wx.TOP | wx.BOTTOM, border=3)

        hboxLoginServerPort = wx.BoxSizer(wx.HORIZONTAL)
        hboxLoginServerPort.Add(textLoginServerPort, proportion=1, flag=wx.TOP | wx.BOTTOM, border=6)
        hboxLoginServerPort.Add(self.inputLoginServerPort, proportion=3, flag=wx.TOP | wx.BOTTOM, border=3)

        hboxLoginButton = wx.BoxSizer(wx.HORIZONTAL)
        hboxLoginButton.Add(self.textTipsMessage, proportion=1, flag=wx.TOP | wx.BOTTOM, border=12)
        hboxLoginButton.Add(ButtonLogin, proportion=0, flag=wx.TOP | wx.BOTTOM, border=6)
        hboxLoginButton.Add(ButtonRegister, proportion=0, flag=wx.TOP | wx.BOTTOM | wx.LEFT, border=6)

        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox_all = wx.BoxSizer(wx.VERTICAL)
        vbox_all.Add(hboxLoginTitle, proportion=0, flag=wx.EXPAND | wx.ALL, border=20)
        vbox.Add(hboxLoginUserName, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5)
        vbox.Add(hboxLoginUserPassword, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5)
        vbox.Add(hboxLoginServerURL, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5)
        vbox.Add(hboxLoginServerPort, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5)

        choice_login_box = wx.BoxSizer(wx.VERTICAL)
        choice_login_list = [u"摄像机", u"服务器", u"测试环境", u"HIS环境", u"环境检测", u"执行机", u"多态", u"脚本开发", u"脚本验收", u"流水线",
                             u"智能分析", u"脚本比较", u"模拟IPC"]
        self.choice_login = wx.CheckListBox(bkg, -1, size=(100, 117), choices=choice_login_list)
        choice_login_box.Add(self.choice_login, proportion=0, flag=wx.EXPAND | wx.UP, border=3)

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(vbox, proportion=0, flag=wx.EXPAND | wx.LEFT, border=100)
        hbox.Add(choice_login_box, proportion=0, flag=wx.EXPAND | wx.LEFT, border=100)
        vbox_all.Add(hbox, proportion=0, flag= wx.ALIGN_RIGHT | wx.LEFT | wx.RIGHT, border=0)
        vbox_all.Add(hboxLoginButton, proportion=0, flag= wx.ALIGN_RIGHT | wx.LEFT | wx.RIGHT, border=100)

        bkg.SetSizer(vbox_all)

        # f = open("config/Login_DefaultUser.cfg", "r")
        # lines = f.readlines()
        # f.close()
        # for line in lines:
        #     if "username" in line:
        #         self.inputLoginUserName.SetValue(line.split("=")[1].split("\n")[0])
        #     if "password" in line:
        #         self.inputLoginUserPassword.SetValue(line.split("=")[1].split("\n")[0])
        #     if "itc_server_ip" in line:
        #         self.combox_inputLoginServerURL.SetValue(line.split("=")[1].split("\n")[0])
        #     if "itc_server_port" in line:
        #         self.inputLoginServerPort.SetValue(line.split("=")[1].split("\n")[0])
        #     if "choice_page" in line:
        #         history_choice_page_list = line.split("=")[1].split("\n")[0].split(",")
        #         for i in range(len(choice_login_list)):
        #             if choice_login_list[i] in history_choice_page_list:
        #                 self.choice_login.Check(i, True)
        self.LoginWindow.Show()

    def LogonTSL(self, event):
        """
        注册界面处理逻辑
        :param event:
        :return:
        """
        logon_dialog = dialog_box.LogonDialog(self.parent, -1, u"注册")
        return True

    def loginTSL(self, event):
        """
        登录界面处理逻辑
        :param event:
        :return:
        """
        self.textTipsMessage.SetValue("")
        config_file_list = [
            r"C:\itc_config_TSL_Username_List.ini",
            r"C:\itc_config_TSL_Username_Dic.ini",
            r"C:\itc_config_Camera_Network_Parameter_List.ini",
            r"C:\itc_config_Server_Network_Parameter_List.ini",
            r"C:\itc_config_Product_List.ini",
            r"C:\itc_config_Product_Server_List.ini",
            r"C:\itc_config_Product_Manufactor_List.ini",
            r"C:\itc_config_Device_Usage_List.ini",
            r"C:\itc_config_Device_Os_Type_List.ini",
            r"C:\itc_config_AttributeNameAndNodeDecMap1.ini",
            r"C:\itc_config_AttributeKeyAndNodeCodeMap1.ini",
            r"C:\itc_config_Org1_Org2_Map.ini",
            r"C:\itc_config_Test_Bed_List.ini",
        ]
        for file in config_file_list:
            if os.path.exists(file):
                os.remove(file)

        username = self.inputLoginUserName.GetValue()
        if username == "":
            self.textTipsMessage.SetValue(u"用户名不能为空！")
            return
        password = self.inputLoginUserPassword.GetValue()
        if password == "":
            self.textTipsMessage.SetValue(u"密码不能为空！")
            return
        url = self.combox_inputLoginServerURL.GetValue()
        if not common_functions.ip_check(url):
            self.textTipsMessage.SetValue(u"IP地址不合法！")
            return
        port = self.inputLoginServerPort.GetValue()
        if not port.isdigit():
            self.textTipsMessage.SetValue(u"端口错误，必须为1-65535数字！")
            return
        port = int(port)

        # 连接服务器
        global Login_Process_DLG
        Login_Process_DLG = wx.ProgressDialog(u"系统初始化...", u"请稍等", maximum=100, parent=self.LoginWindow,
                                              style=0 | wx.PD_APP_MODAL | wx.PD_CAN_ABORT | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME)
        self.TSLConnect = tsl_scripts.TSLInterface(username, password, url, port)
        try:
            Login_Process_DLG.Update(0, u"登录账号")
            result = self.TSLConnect.TSL_Login()
            if result != "0":
                self.textTipsMessage.SetValue(result_code.RES_CODE[result])
                Login_Process_DLG.Destroy()
                return
            else:
                user_dec = self.TSLConnect.TSL_Get_User_Dec_By_Username(username)
                global TSLS_URL
                TSLS_URL = url
                global TSLS_PORT
                TSLS_PORT = port
                global TSLS_USERNAME
                TSLS_USERNAME = username
                global TSLS_User_Dec
                TSLS_User_Dec = user_dec
                global TSLS_PASSWORD
                TSLS_PASSWORD = password

                # check update
                # Login_Process_DLG.Update(5, u"检查客户端脚本")
                # currentVersion = version.VERSION
                # result = self.TSLConnect.TSL_Getinfo_Client_Update(currentVersion)
                # if result.split("::")[0] == "1033":
                #     self.textTipsMessage.SetValue(resultCode.resCode["1033"])
                #     Login_Process_DLG.Destroy()
                #     return
                f = open("config/Login_DefaultUser.cfg", "r")
                lines = f.readlines()
                f.close()
                for i in range(len(lines)):
                    if "username" in lines[i]:
                        lines[i] = "username=" + TSLS_USERNAME + "\n"
                    if "password" in lines[i]:
                        lines[i] = "password=" + TSLS_PASSWORD + "\n"
                    if "itc_server_ip" in lines[i]:
                        lines[i] = "itc_server_ip=" + TSLS_URL + "\n"
                    if "itc_server_port" in lines[i]:
                        lines[i] = "itc_server_port=" + str(TSLS_PORT) + "\n"
                    if "choice_page" in lines[i]:
                        lines[i] = "choice_page=" + ",".join(list(self.choice_login.GetCheckedStrings())) + "\n"
                f = open("config/Login_DefaultUser", "w")
                f.writelines(lines)
                f.close()
                theWorkFrame = WorkSpaceFrame()
                checked_list = self.choice_login.GetCheckedStrings()
                theWorkFrame.CreatePages(checked_list)
                Login_Process_DLG.Destroy()
                self.LoginWindow.Close()
                return
        except:
            logger.info(traceback.format_exc())
            Login_Process_DLG.Destroy()
            dlg = wx.MessageDialog(self.parent, u"页面加载失败！", 'notice', wx.YES_NO | wx.YES_DEFAULT | wx.ICON_WARNING)
            val = dlg.ShowModal()
            dlg.Destroy()
            return


class WorkSpaceFrame(LoginFrame):
    """
    工作区界面
    """

    def __init__(self):
        context.APP = self
        context.username = TSLS_USERNAME
        self.TSLConnect = tsl_scripts.TSLInterface(TSLS_USERNAME, TSLS_PASSWORD, TSLS_URL, TSLS_PORT)

    def OnPageChanged(self, event):
        old = event.GetOldSelection()
        new = event.GetSelection()
        sel = self.toolPages.GetSelection()
        # logger.info('OnPageChanged,  old:%d, new:%d, sel:%d\n' % (old, new, sel))
        event.Skip()

    def CreatePages(self, checked_list):
        # 创建工作界面
        self.WorkSpaceWindow = wx.Frame(parent=None,
                                        title='（iTC）Intelligent Test Center V%s (User:%s Server:%s)' % (
                                            VERSION, TSLS_USERNAME, TSLS_URL))
        self.WorkSpaceWindow.Bind(wx.EVT_CLOSE, self.__ExitProgram)
        self.toolPages = wx.Toolbook(parent=self.WorkSpaceWindow, id=-1, style=wx.BK_BOTTOM)
        self.toolPages.SetBackgroundColour(wx.Colour(255, 255, 255))
        # image
        il = wx.ImageList(60, 70)
        bmpCameraTest = wx.Image('static\image\CaneraTest.bmp', wx.BITMAP_TYPE_BMP).ConvertToBitmap()
        # bmpCameraTest = wx.Image('static\image\CaneraTest.bmp',wx.BITMAP_TYPE_BMP).ConvertToBitmap()
        index1 = il.Add(bmpCameraTest)
        index8 = il.Add(bmpCameraTest)
        index10 = il.Add(bmpCameraTest)
        index19 = il.Add(bmpCameraTest)
        self.toolPages.AssignImageList(il)
        # 添加子页面
        page_name_list = [u"自动化资源和信息", u"人力地图", u"测试活动日报", u"摄像机测试环境管理", u"服务器设备管理", u"机框和散件管理", u"测试环境管理", u"设备利用率统计",
                          u"AutoSpace执行机管理",
                          u"IPC多态测试记录", u"脚本快速验收上线系统", u"用户中心", u"环境信息与状态监测", u"流水线大数据系统", u"项目级流水线展示", u"脚本敏捷开发系统",
                          u"智能分析TLV数据分析",
                          u"脚本比较", u"模拟IPC环境管理", u"HIS测试环境管理"]
        login_process_count = int(1 * 100 / (len(page_name_list) + 1))
        Login_Process_DLG.Update(login_process_count, u"初始化页面:" + page_name_list[0])
        toolPage = ToolPage(self.toolPages, 1, page_name_list[0])
        toolPage = toolPage.NoticePage()
        self.toolPages.AddPage(toolPage, "", imageId=index1)

        if u"摄像机" in checked_list:
            login_process_count = int(2 * 100 / (len(page_name_list) + 1))
            Login_Process_DLG.Update(login_process_count, u"初始化页面:" + page_name_list[3])
            toolPage1 = ToolPage(self.toolPages, 4, page_name_list[3])
            toolPage = toolPage1.MakeToolPageApplyResource()
            self.toolPages.AddPage(toolPage, "", imageId=index1)

        login_process_count = int(14 * 100 / (len(page_name_list) + 1))
        Login_Process_DLG.Update(login_process_count, u"初始化页面:" + page_name_list[1])
        toolPage8 = ToolPage(self.toolPages, 2, page_name_list[1])
        toolPage = toolPage8.PeopleMap()
        self.toolPages.AddPage(toolPage, "", imageId=index8)

        login_process_count = int(13 * 100 / (len(page_name_list) + 1))
        Login_Process_DLG.Update(login_process_count, u"初始化页面:" + page_name_list[11])
        toolPage10 = ToolPage(self.toolPages, 12, page_name_list[11])
        toolPage = toolPage10.UserPage()
        self.toolPages.AddPage(toolPage, "", imageId=index10)

        if u"模拟IPC" in checked_list:
            login_process_count = 16 * 100 / (len(page_name_list) + 1)
            Login_Process_DLG.Update(login_process_count, u"初始化页面:" + page_name_list[18])
            toolPage18 = ToolPage(self.toolPages, 19, page_name_list[18])
            toolPage = toolPage18.MakeToolPageApplyVirTualResource()
            self.toolPages.AddPage(toolPage, "", imageId=index19)

        self.toolPages.Bind(wx.EVT_TOOLBOOK_PAGE_CHANGED, self.OnPageChanged)
        self.WorkSpaceWindow.Maximize()
        self.WorkSpaceWindow.Show()

    def __ExitProgram(self, evt):
        sys.exit()

    def Get_TSL_Username_List(self):
        self.usernamelist = ["admin"]
        return self.usernamelist

    def Get_Camera_Network_Parameter_List(self):
        self.cameranetworkparameterlist = ["admin", "123456"]
        return self.cameranetworkparameterlist

    def Get_Test_Bed_List(self):
        self.Env_TestBed_List = ["shipao", "daily"]
        return self.Env_TestBed_List

    def Get_Product_List(self):
        self.productlist = ["VCN", "VCM", "IPC"]
        return self.productlist

    def Get_Device_Usage_List(self):
        self.Device_Usage_List = ["手工测试", "自动化测试"]
        return self.Device_Usage_List

    def Get_Product_Manufactor_List(self):
        self.productmanufactorlist = ["H3C", "HUAWEI"]
        return self.productmanufactorlist

    def Get_Org1_Org2_Map(self):
        self.Org1_Org2_Map = {"IPC": [u"SDC测试", u"SDC开发"]}
        return self.Org1_Org2_Map

    def Get_Camera_Attribute_List(self):
        self.Camera_Attribute_List = [u"sd_card_status,SD卡,1"]
        return self.Camera_Attribute_List


class ToolPage(WorkSpaceFrame):
    def __init__(self, panent, id, title):
        WorkSpaceFrame.__init__(self)
        self.bkg = wx.Panel(panent, id)
        textTitle = wx.StaticText(self.bkg, -1, title, style=wx.ALIGN_CENTER)
        textTitle.SetForegroundColour('Black')
        textTitle.SetFont(wx.Font(22, wx.SWISS, wx.NORMAL, wx.NORMAL))
        self.textMessage = wx.TextCtrl(self.bkg, -1, u"", style=wx.TE_LEFT | wx.TE_READONLY | wx.BORDER_NONE)

        bmp = wx.Bitmap("static\image\CaneraTest1.bmp", wx.BITMAP_TYPE_BMP)
        mask = wx.Mask(bmp, wx.WHITE)
        bmp.SetMask(mask)
        redmineButton = wx.BitmapButton(self.bkg, -1, bmp, (20, 20), style=wx.CENTER)
        redmineButton.SetToolTip(u"不好用，我要提单！！！")
        redmineButton.Bind(wx.EVT_BUTTON, self.__ClickLinkRedmine)

        # title
        hboxTitle = wx.BoxSizer(wx.HORIZONTAL)
        hboxTitle.Add(textTitle, proportion=1)
        hboxTitle.Add(redmineButton, proportion=0)

        # message
        hboxMessage = wx.BoxSizer(wx.HORIZONTAL)
        hboxMessage.Add(self.textMessage, proportion=1)

        # self.vbox
        self.vbox = wx.BoxSizer(wx.VERTICAL)
        self.vbox.Add(hboxTitle, proportion=0, flag=wx.EXPAND | wx.TOP, border=10)
        self.vbox.Add(hboxMessage, proportion=0, flag=wx.EXPAND | wx.ALL, border=15)

        # 初始化
        self.updateFileUrl = ""

    def NoticePage(self):  # 公告
        theTitle = wx.StaticText(self.bkg, -1, u"自动化公告墙", style=wx.ALIGN_CENTER)
        theTitle.SetFont(wx.Font(16, wx.SCRIPT, wx.NORMAL, wx.LIGHT))
        self.Notice = wx.StaticText(self.bkg, style=wx.VSCROLL | wx.HSCROLL)
        self.__RefreshNotice("")
        buttonNoticeRefresh = wx.Button(self.bkg, label=u"刷新")
        buttonNoticeRefresh.Bind(wx.EVT_BUTTON, self.__RefreshNotice)
        buttonAddNotice = wx.Button(self.bkg, label=u"添加公告")
        buttonAddNotice.Bind(wx.EVT_BUTTON, self.__AddNotice)
        buttonModifyNotice = wx.Button(self.bkg, label=u"修改公告")
        buttonModifyNotice.Bind(wx.EVT_BUTTON, self.__ModifyNotice)

        hboxtitle1 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle1.Add(theTitle, proportion=1)
        hboxtitle12 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle12.Add(self.Notice, proportion=1, flag=wx.EXPAND)
        hboxtitle13 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle13.Add(buttonNoticeRefresh, proportion=0)
        hboxtitle13.Add(buttonAddNotice, proportion=0, flag=wx.LEFT, border=5)
        hboxtitle13.Add(buttonModifyNotice, proportion=0, flag=wx.LEFT, border=5)

        # 链接
        theTitle = wx.StaticText(self.bkg, -1, u"链接及常用信息", style=wx.ALIGN_CENTER)
        theTitle.SetFont(wx.Font(16, wx.SCRIPT, wx.NORMAL, wx.LIGHT))
        self.TestLink = wx.StaticText(self.bkg, style=wx.VSCROLL | wx.HSCROLL)
        self.__RefreshTestLink("")
        buttonTestLinkRefresh = wx.Button(self.bkg, label=u"刷新")
        buttonTestLinkRefresh.Bind(wx.EVT_BUTTON, self.__RefreshTestLink)
        buttonAddTestLink = wx.Button(self.bkg, label=u"添加信息")
        buttonAddTestLink.Bind(wx.EVT_BUTTON, self.__AddTestLink)
        buttonModifyTestLink = wx.Button(self.bkg, label=u"修改信息")
        buttonModifyTestLink.Bind(wx.EVT_BUTTON, self.__ModifyTestLink)

        hboxtitle2 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle2.Add(theTitle, proportion=1)
        hboxtitle22 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle22.Add(self.TestLink, proportion=1, flag=wx.EXPAND)
        hboxtitle23 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle23.Add(buttonTestLinkRefresh, proportion=0)
        hboxtitle23.Add(buttonAddTestLink, proportion=0, flag=wx.LEFT, border=5)
        hboxtitle23.Add(buttonModifyTestLink, proportion=0, flag=wx.LEFT, border=5)

        vbox1 = wx.BoxSizer(wx.VERTICAL)
        vbox1.Add(hboxtitle1, proportion=0, flag=wx.EXPAND)
        vbox1.Add(hboxtitle12, proportion=1, flag=wx.EXPAND)
        vbox1.Add(hboxtitle13, proportion=0, flag=wx.EXPAND | wx.TOP | wx.BOTTOM, border=5)

        vbox2 = wx.BoxSizer(wx.VERTICAL)
        vbox2.Add(hboxtitle2, proportion=0, flag=wx.EXPAND)
        vbox2.Add(hboxtitle22, proportion=1, flag=wx.EXPAND)
        vbox2.Add(hboxtitle23, proportion=0, flag=wx.EXPAND | wx.TOP | wx.BOTTOM, border=5)

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(vbox1, proportion=1, flag=wx.EXPAND)
        hbox.Add(vbox2, proportion=1, flag=wx.EXPAND | wx.LEFT, border=20)

        self.vbox.Add(hbox, proportion=1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=20)
        self.bkg.SetSizer(self.vbox)
        return self.bkg

    def MakeToolPageApplyResource(self):  # 摄像机界面
        WorkSpaceFrame.Get_TSL_Username_List(self)
        WorkSpaceFrame.Get_Camera_Attribute_List(self)
        WorkSpaceFrame.Get_Camera_Network_Parameter_List(self)
        WorkSpaceFrame.Get_Product_List(self)
        WorkSpaceFrame.Get_Device_Usage_List(self)
        WorkSpaceFrame.Get_Org1_Org2_Map(self)
        WorkSpaceFrame.Get_Product_Manufactor_List(self)
        WorkSpaceFrame.Get_Test_Bed_List(self)
        #
        # theTitle = wx.StaticText(self.bkg, -1, u"摄像机测试环境管理", style=wx.ALIGN_CENTER)
        # theTitle.SetFont(wx.Font(16, wx.SCRIPT, wx.NORMAL, wx.LIGHT))
        self.__CameraInfoWindow()
        #
        self.attributeNameAndNodeDecMap = {}  # 属性名称和节点描述
        self.attributeKeyAndNodeCodeMap = {}  # 属性关键字和节点代码字典
        self.attributeNameAndKeyMap = {}  # 属性名称和关键字字典

        # 测试床， 部门，组织， 用途， 挂账人， 厂商
        self.attributeNameAndNodeDecMap[u"测试床"] = self.Env_TestBed_List
        self.attributeNameAndKeyMap[u"测试床"] = "test_bed_name"
        self.attributeKeyAndNodeCodeMap["test_bed_name"] = self.Env_TestBed_List
        Org1_list = []
        for i in self.Org1_Org2_Map:
            Org1_list.append(i)
        self.attributeNameAndNodeDecMap[u"产品组"] = Org1_list
        self.attributeNameAndKeyMap[u"产品组"] = "org"
        self.attributeKeyAndNodeCodeMap["org"] = Org1_list
        Org2_list = []
        for i in self.Org1_Org2_Map:
            Org2_list = Org2_list + self.Org1_Org2_Map[i]
        self.attributeKeyAndNodeCodeMap[u"组织"] = Org2_list
        self.attributeNameAndKeyMap[u"组织"] = "org2"
        self.attributeKeyAndNodeCodeMap["org"] = Org2_list

        self.attributeNameAndNodeDecMap[u"用途"] = self.Device_Usage_List
        self.attributeNameAndKeyMap[u"用途"] = "usage"
        self.attributeKeyAndNodeCodeMap["usage"] = self.Device_Usage_List

        # 设备型号，设备型号属性，其他属性
        for i in self.Camera_Attribute_List:
            attributeKeyAndNameList = i.split(",")
            is_display = attributeKeyAndNameList[2]  # 是否在申请条件中显示
            if is_display == "0":
                continue
            attributeKey = attributeKeyAndNameList[0]  # 属性关键字
            attributeName = attributeKeyAndNameList[1]
            self.attributeNameAndKeyMap[attributeName] = attributeKey
            # attributeNodeList = (self.TSLConnect.TSL_Get_Attribute_Node_List(attributeKey).split(","))
            attributeNodeList = [u"sd_card_status,SD卡,1", u"org,组织", u"测试床,V5R19C20", u"用途,手工测试"]
            theNodeCodeList = []
            theNodeDecList = []
            for j in attributeNodeList:
                attributeNodeKeyAndDecList = j.split(",")
                attributeNodeCode = attributeNodeKeyAndDecList[0]
                attributeNodeDec = attributeNodeKeyAndDecList[1]
                theNodeCodeList.append(attributeNodeCode)  # 属性取值
                theNodeDecList.append(attributeNodeDec)  # 属性描述取值
            self.attributeNameAndNodeDecMap[attributeName] = theNodeDecList
            self.attributeKeyAndNodeCodeMap[attributeKey] = theNodeCodeList

        # 条件筛选
        self.allApplyComboxList = []
        self.allApplyInputMap = []
        self.attributeNameAndNodeDecMap = {u"测试床": ["ENV_AutoTest_V5R19C20", "ENV_AutoTest_3516E"],
                                           u"组织": [u"测试组", u"开发组"], u"用途": [u"手工测试", u"自动化测试"],
                                           u"产品组": ["PDT", "IPC", "IVS"]}
        vbox1 = self.__ApplyResourceListMenu(self.attributeNameAndNodeDecMap)
        defaultInputButton = wx.Button(self.bkg, label=u"重置")
        defaultInputButton.Bind(wx.EVT_BUTTON, self.__SetAttributeInputNull)
        applyButton = wx.Button(self.bkg, label=u"搜索摄像机")
        applyButton.Bind(wx.EVT_BUTTON, self.__applyDeviceListByAttribute)
        hboxButton = wx.BoxSizer(wx.HORIZONTAL)
        hboxButton.Add(defaultInputButton, proportion=0, flag=wx.EXPAND | wx.LEFT, border=30)
        hboxButton.Add(applyButton, proportion=1, flag=wx.EXPAND | wx.LEFT, border=5)
        vbox1.Add(hboxButton, proportion=0, flag=wx.EXPAND | wx.TOP, border=30)
        # vbox1.Add(theTitle,proportion=1, flag=wx.EXPAND | wx.TOP |wx.ALIGN_CENTER, border=30 )

        # 筛选按钮
        self.filter_button = wx.Button(self.bkg, label=u"按条件筛选（未设置）")
        self.filter_button.Bind(wx.EVT_BUTTON, self.__CreateFilterWindow)
        self.filter_button.Enable(False)
        menu_button = wx.Button(self.bkg, label=u"")
        menu_button.Bind(wx.EVT_BUTTON, lambda evt, flag=1: self.__setServerMenu(evt, flag))

        # 查找结果显示列
        # if not os.path.exists("D:\\local_camera_menu.cfg"):
        #     shutil.copy("config/MENU_Camera.cfg", "D:\\local_camera_menu.cfg")
        # f = open("config/MENU_Camera.cfg", "r", encoding='utf-8')
        # lines = f.readlines()
        # f.close()
        # self.menuAllDeviceForm = lines[0].split("\n")[0].split(",")
        # for i in range(len(self.menuAllDeviceForm)):
        #     self.menuAllDeviceForm[i] = self.menuAllDeviceForm[i].decode("utf-8")
        # logger.info self.menuAllDeviceForm
        # 如下
        self.menuAllDeviceForm = [u"当前所属测试床", u"型号", u"软件版本号", u"软件版本时间", u"设备IP", u"网络状态", u"当前使用人", u"使用人IP",
                                  u"开始使用时间", u"可用时长",
                                  u"SD容量", u"SN号", u"安装位置", u"部门", u"厂商", u"组织", u"产品类型", u"一周利用率", u"LCBB设备", u"设备挂账人",
                                  u"备注一", u"备注二", u"升级计划"]
        self.AllDeviceListForm = DataListViewForm(self.bkg, self.menuAllDeviceForm)
        vbox3 = wx.BoxSizer(wx.HORIZONTAL)
        vbox3.Add(self.filter_button, proportion=0, flag=wx.BOTTOM, border=5)
        vbox3.Add(menu_button, proportion=0, flag=wx.BOTTOM, border=5)

        vbox2 = wx.BoxSizer(wx.VERTICAL)
        vbox2.Add(vbox3, proportion=0, flag=wx.EXPAND | wx.TOP, border=10)
        vbox2.Add(self.AllDeviceListForm.dvc, proportion=1, flag=wx.EXPAND)

        self.lockButton = wx.Button(self.bkg, label=u"使用锁定")
        self.lockButton.Bind(wx.EVT_BUTTON, self.__LockSelectDeviceList)
        self.lockTimeCombox = wx.ComboBox(self.bkg, -1, value="1小时",
                                          choices=[u"10分钟", u"6小时", u"1天", u"1周", u"1月", u"永久"], style=wx.CB_DROPDOWN)

        self.unlockButton = wx.Button(self.bkg, label=u"释放")
        self.unlockButton.Bind(wx.EVT_BUTTON, self.__unLockSelectDeviceList)

        myResourceButton = wx.Button(self.bkg, label=u"我的资源")
        myResourceButton.Bind(wx.EVT_BUTTON, self.__GetMyDeviceList)

        unlockButtonwo = wx.Button(self.bkg, label=u"释放ENV设备")
        unlockButtonwo.Bind(wx.EVT_BUTTON, self.__unLockSelectDeviceListWo)

        updateButton = wx.Button(self.bkg, label=u"摄像机升级")
        updateButton.Bind(wx.EVT_BUTTON, self.__updateDevice)

        updateBedNameButton = wx.Button(self.bkg, label=u"摄像机升级（根据测试床）")
        updateBedNameButton.Bind(wx.EVT_BUTTON, self.__updateDeviceByBedNameWindow)

        deletePlanButton = wx.Button(self.bkg, label=u"删除定时升级任务")
        deletePlanButton.Bind(wx.EVT_BUTTON, self.__deletePlan_update)

        restoreButton = wx.Button(self.bkg, label=u"简单恢复默认配置")
        restoreButton.Bind(wx.EVT_BUTTON, self.__restoreDevice)

        SFTPEnableButton = wx.Button(self.bkg, label=u"启用SFTP")
        SFTPEnableButton.Bind(wx.EVT_BUTTON, self.__SFTPEnable)

        SSHEnableButton = wx.Button(self.bkg, label=u"启用SSH")
        SSHEnableButton.Bind(wx.EVT_BUTTON, self.__SSHEnable)

        SetNTPTimeButton = wx.Button(self.bkg, label=u"设置NTP同步时间")
        SetNTPTimeButton.Bind(wx.EVT_BUTTON, self.__SetNTPTime)

        collectLLDataButton = wx.Button(self.bkg, label=u"代码覆盖率:收集")
        collectLLDataButton.Bind(wx.EVT_BUTTON, self.__collectLLTDataDevice)

        deleteLLDataButton = wx.Button(self.bkg, label=u"代码覆盖率:清理")
        deleteLLDataButton.Bind(wx.EVT_BUTTON, self.__deleteLLTDataDevice)

        topoButton = wx.Button(self.bkg, label=u"一键刷新TOPO环境")
        topoButton.Bind(wx.EVT_BUTTON, self.__sendCreateBaseTOPOInfo)

        addCameraButton = wx.Button(self.bkg, label=u"添加摄像机")
        addCameraButton.Bind(wx.EVT_BUTTON, self.__addCamera)
        deleteCameraButton = wx.Button(self.bkg, label=u"删除摄像机")
        deleteCameraButton.Bind(wx.EVT_BUTTON, self.__deleteCamera)
        modifyCameraButton = wx.Button(self.bkg, label=u"修改摄像机")
        modifyCameraButton.Bind(wx.EVT_BUTTON, self.__ModifyCamera)
        modifyCameraIPButton = wx.Button(self.bkg, label=u"修改摄像机IP")
        modifyCameraIPButton.Bind(wx.EVT_BUTTON, self.__ModifyCameraIP)

        exportCameraButton = wx.Button(self.bkg, label=u"导出")
        exportCameraButton.Bind(wx.EVT_BUTTON, lambda evt, flag=1: self.__exportServer(evt, flag))

        mailButton = wx.Button(self.bkg, label=u"邮件")
        mailButton.Bind(wx.EVT_BUTTON, self.__sendIPCMailWindow)

        configQQLDButton = wx.Button(self.bkg, label=u"配置为枪球联动关系")
        configQQLDButton.Bind(wx.EVT_BUTTON, self.__configQQLDB)

        unConfigQQLDButton = wx.Button(self.bkg, label=u"取消配置为枪球联动关系")
        unConfigQQLDButton.Bind(wx.EVT_BUTTON, self.__unConfigQQLDB)

        saveUpdateFileButton = wx.Button(self.bkg, label=u"备份升级文件")
        saveUpdateFileButton.Bind(wx.EVT_BUTTON, self.__saveUpdateFile)

        SDCardFormatButton = wx.Button(self.bkg, label=u"SD卡格式化")
        SDCardFormatButton.Bind(wx.EVT_BUTTON, self.__SDCardFormat)

        refreshIPCVersionButton = wx.Button(self.bkg, label=u"刷新版本")
        refreshIPCVersionButton.Bind(wx.EVT_BUTTON, self.__refreshIPCVersion)

        refreshIPCNetWorkButton = wx.Button(self.bkg, label=u"刷新网络状态")
        refreshIPCNetWorkButton.Bind(wx.EVT_BUTTON, self.__refreshIPCNetWork)

        refreshIPCNetWorkParameterButton = wx.Button(self.bkg, label=u"刷新网络参数")
        refreshIPCNetWorkParameterButton.Bind(wx.EVT_BUTTON, self.__refreshIPCNetWorkParameter)

        refreshIPCSDCardButton = wx.Button(self.bkg, label=u"刷新网络参数")
        refreshIPCSDCardButton.Bind(wx.EVT_BUTTON, self.__refreshIPCSDCard)

        # 批量添加网络IPC
        addMoreIPCButton = wx.Button(self.bkg, label=u"批量添加IPC")
        addMoreIPCButton.Bind(wx.EVT_BUTTON, self.__addMoreIPC)

        # 手动释放IPC物料表状态
        self.manualUnlockButton = wx.Button(self.bkg, label=u"手动释放IPC")
        self.manualUnlockButton.Bind(wx.EVT_BUTTON, self.__ManualReleaseIPC)

        if TSLS_USERNAME != 'admin':
            addCameraButton.Enable(False)
            deleteCameraButton.Enable(False)
            modifyCameraButton.Enable(False)
        self.currentFormData = "NULL"
        self.__EnableLockAndUnlockButton("")

        # 布局
        hboxApplyButton = wx.BoxSizer(wx.HORIZONTAL)
        hboxApplyButton.Add(self.lockButton, proportion=0)
        hboxApplyButton.Add(self.lockTimeCombox, proportion=0, flag=wx.EXPAND | wx.LEFT, border=5)
        hboxApplyButton.Add(self.unlockButton, proportion=0, flag=wx.EXPAND | wx.LEFT, border=20)
        hboxApplyButton.Add(myResourceButton, proportion=0, flag=wx.EXPAND | wx.LEFT, border=20)
        hboxApplyButton.Add(unlockButtonwo, proportion=0, flag=wx.EXPAND | wx.LEFT, border=20)

        hboxManagementButton = wx.BoxSizer(wx.HORIZONTAL)
        hboxManagementButton.Add(updateButton, proportion=0)
        hboxManagementButton.Add(updateBedNameButton, proportion=0, flag=wx.LEFT, border=10)
        hboxManagementButton.Add(deletePlanButton, proportion=0, flag=wx.LEFT, border=10)
        hboxManagementButton.Add(addMoreIPCButton, proportion=0, flag=wx.LEFT, border=10)

        hboxManagementButton4 = wx.BoxSizer(wx.HORIZONTAL)
        hboxManagementButton4.Add(restoreButton, proportion=0)
        hboxManagementButton4.Add(SFTPEnableButton, proportion=0, flag=wx.LEFT, border=10)
        hboxManagementButton4.Add(SSHEnableButton, proportion=0, flag=wx.LEFT, border=10)
        hboxManagementButton4.Add(SetNTPTimeButton, proportion=0, flag=wx.LEFT, border=10)
        hboxManagementButton4.Add(deleteLLDataButton, proportion=0, flag=wx.LEFT, border=10)
        hboxManagementButton4.Add(collectLLDataButton, proportion=0, flag=wx.LEFT, border=10)
        hboxManagementButton4.Add(topoButton, proportion=0, flag=wx.LEFT, border=10)
        hboxManagementButton4.Add(saveUpdateFileButton, proportion=0, flag=wx.LEFT, border=10)
        hboxManagementButton4.Add(SDCardFormatButton, proportion=0, flag=wx.LEFT, border=10)

        hboxManagementButton2 = wx.BoxSizer(wx.HORIZONTAL)
        hboxManagementButton2.Add(addCameraButton, proportion=0)
        hboxManagementButton2.Add(modifyCameraButton, proportion=0, flag=wx.LEFT, border=10)
        hboxManagementButton2.Add(modifyCameraIPButton, proportion=0, flag=wx.LEFT, border=10)
        hboxManagementButton2.Add(deleteCameraButton, proportion=0, flag=wx.LEFT, border=10)
        hboxManagementButton2.Add(exportCameraButton, proportion=0, flag=wx.LEFT, border=10)
        hboxManagementButton2.Add(mailButton, proportion=0, flag=wx.LEFT, border=10)
        hboxManagementButton2.Add(configQQLDButton, proportion=0, flag=wx.EXPAND | wx.LEFT, border=10)
        hboxManagementButton2.Add(unConfigQQLDButton, proportion=0, flag=wx.EXPAND | wx.LEFT, border=10)

        hboxManagementButton3 = wx.BoxSizer(wx.HORIZONTAL)
        hboxManagementButton3.Add(refreshIPCVersionButton, proportion=0)
        hboxManagementButton3.Add(refreshIPCNetWorkButton, proportion=0, flag=wx.EXPAND | wx.LEFT, border=10)
        hboxManagementButton3.Add(refreshIPCNetWorkParameterButton, proportion=0, flag=wx.EXPAND | wx.LEFT, border=10)
        hboxManagementButton3.Add(refreshIPCSDCardButton, proportion=0, flag=wx.EXPAND | wx.LEFT, border=10)
        hboxManagementButton3.Add(self.manualUnlockButton, proportion=0, flag=wx.EXPAND | wx.LEFT, border=10)

        vbox2.Add(hboxApplyButton, proportion=0, flag=wx.EXPAND | wx.TOP, border=20)
        vbox2.Add(hboxManagementButton2, proportion=0, flag=wx.EXPAND | wx.TOP, border=10)
        vbox2.Add(hboxManagementButton, proportion=0, flag=wx.EXPAND | wx.TOP, border=10)
        vbox2.Add(hboxManagementButton4, proportion=0, flag=wx.EXPAND | wx.TOP, border=10)
        vbox2.Add(hboxManagementButton3, proportion=0, flag=wx.EXPAND | wx.TOP, border=10)

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(vbox1, proportion=1, flag=wx.EXPAND | wx.LEFT, border=10)
        hbox.Add(vbox2, proportion=6, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=10)
        self.vbox.Add(hbox, proportion=1, flag=wx.EXPAND | wx.TOP, border=20)
        self.bkg.SetSizer(self.vbox)
        return self.bkg

    def PeopleMap(self):  # 人力地图
        WorkSpaceFrame.Get_TSL_Username_List(self)
        theTitle = wx.StaticText(self.bkg, -1, u"人力地图", style=wx.ALIGN_CENTER)
        theTitle.SetFont(wx.Font(16, wx.SCRIPT, wx.NORMAL, wx.LIGHT))
        self.Notice = wx.StaticText(self.bkg, style=wx.VSCROLL | wx.HSCROLL)
        self.__RefreshNotice("")
        buttonNoticeRefresh = wx.Button(self.bkg, label=u"刷新")
        buttonNoticeRefresh.Bind(wx.EVT_BUTTON, self.__RefreshNotice)
        buttonAddNotice = wx.Button(self.bkg, label=u"添加公告")
        buttonAddNotice.Bind(wx.EVT_BUTTON, self.__AddNotice)
        buttonModifyNotice = wx.Button(self.bkg, label=u"修改公告")
        buttonModifyNotice.Bind(wx.EVT_BUTTON, self.__ModifyNotice)

        hboxtitle1 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle1.Add(theTitle, proportion=1)
        hboxtitle12 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle12.Add(self.Notice, proportion=1, flag=wx.EXPAND)
        hboxtitle13 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle13.Add(buttonNoticeRefresh, proportion=0)
        hboxtitle13.Add(buttonAddNotice, proportion=0, flag=wx.LEFT, border=5)
        hboxtitle13.Add(buttonModifyNotice, proportion=0, flag=wx.LEFT, border=5)

        # 链接
        theTitle = wx.StaticText(self.bkg, -1, u"链接及常用信息", style=wx.ALIGN_CENTER)
        theTitle.SetFont(wx.Font(16, wx.SCRIPT, wx.NORMAL, wx.LIGHT))
        self.TestLink = wx.StaticText(self.bkg, style=wx.VSCROLL | wx.HSCROLL)
        self.__RefreshTestLink("")
        buttonTestLinkRefresh = wx.Button(self.bkg, label=u"刷新")
        buttonTestLinkRefresh.Bind(wx.EVT_BUTTON, self.__RefreshTestLink)
        buttonAddTestLink = wx.Button(self.bkg, label=u"添加信息")
        buttonAddTestLink.Bind(wx.EVT_BUTTON, self.__AddTestLink)
        buttonModifyTestLink = wx.Button(self.bkg, label=u"修改信息")
        buttonModifyTestLink.Bind(wx.EVT_BUTTON, self.__ModifyTestLink)

        hboxtitle2 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle2.Add(theTitle, proportion=1)
        hboxtitle22 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle22.Add(self.TestLink, proportion=1, flag=wx.EXPAND)
        hboxtitle23 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle23.Add(buttonTestLinkRefresh, proportion=0)
        hboxtitle23.Add(buttonAddTestLink, proportion=0, flag=wx.LEFT, border=5)
        hboxtitle23.Add(buttonModifyTestLink, proportion=0, flag=wx.LEFT, border=5)

        vbox1 = wx.BoxSizer(wx.VERTICAL)
        vbox1.Add(hboxtitle1, proportion=0, flag=wx.EXPAND)
        vbox1.Add(hboxtitle12, proportion=1, flag=wx.EXPAND)
        vbox1.Add(hboxtitle13, proportion=0, flag=wx.EXPAND | wx.TOP | wx.BOTTOM, border=5)

        vbox2 = wx.BoxSizer(wx.VERTICAL)
        vbox2.Add(hboxtitle2, proportion=0, flag=wx.EXPAND)
        vbox2.Add(hboxtitle22, proportion=1, flag=wx.EXPAND)
        vbox2.Add(hboxtitle23, proportion=0, flag=wx.EXPAND | wx.TOP | wx.BOTTOM, border=5)

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(vbox1, proportion=1, flag=wx.EXPAND)
        hbox.Add(vbox2, proportion=1, flag=wx.EXPAND | wx.LEFT, border=20)

        self.vbox.Add(hbox, proportion=1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=20)
        self.bkg.SetSizer(self.vbox)
        return self.bkg

    def UserPage(self):  # 用户列表
        WorkSpaceFrame.Get_TSL_Username_List(self)
        theTitle = wx.StaticText(self.bkg, -1, u"用户中心", style=wx.ALIGN_CENTER)
        theTitle.SetFont(wx.Font(16, wx.SCRIPT, wx.NORMAL, wx.LIGHT))
        self.Notice = wx.StaticText(self.bkg, style=wx.VSCROLL | wx.HSCROLL)
        self.__RefreshNotice("")
        buttonNoticeRefresh = wx.Button(self.bkg, label=u"刷新")
        buttonNoticeRefresh.Bind(wx.EVT_BUTTON, self.__RefreshNotice)
        buttonAddNotice = wx.Button(self.bkg, label=u"添加公告")
        buttonAddNotice.Bind(wx.EVT_BUTTON, self.__AddNotice)
        buttonModifyNotice = wx.Button(self.bkg, label=u"修改公告")
        buttonModifyNotice.Bind(wx.EVT_BUTTON, self.__ModifyNotice)

        hboxtitle1 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle1.Add(theTitle, proportion=1)
        hboxtitle12 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle12.Add(self.Notice, proportion=1, flag=wx.EXPAND)
        hboxtitle13 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle13.Add(buttonNoticeRefresh, proportion=0)
        hboxtitle13.Add(buttonAddNotice, proportion=0, flag=wx.LEFT, border=5)
        hboxtitle13.Add(buttonModifyNotice, proportion=0, flag=wx.LEFT, border=5)

        # 链接
        theTitle = wx.StaticText(self.bkg, -1, u"链接及常用信息", style=wx.ALIGN_CENTER)
        theTitle.SetFont(wx.Font(16, wx.SCRIPT, wx.NORMAL, wx.LIGHT))
        self.TestLink = wx.StaticText(self.bkg, style=wx.VSCROLL | wx.HSCROLL)
        self.__RefreshTestLink("")
        buttonTestLinkRefresh = wx.Button(self.bkg, label=u"刷新")
        buttonTestLinkRefresh.Bind(wx.EVT_BUTTON, self.__RefreshTestLink)
        buttonAddTestLink = wx.Button(self.bkg, label=u"添加信息")
        buttonAddTestLink.Bind(wx.EVT_BUTTON, self.__AddTestLink)
        buttonModifyTestLink = wx.Button(self.bkg, label=u"修改信息")
        buttonModifyTestLink.Bind(wx.EVT_BUTTON, self.__ModifyTestLink)

        hboxtitle2 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle2.Add(theTitle, proportion=1)
        hboxtitle22 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle22.Add(self.TestLink, proportion=1, flag=wx.EXPAND)
        hboxtitle23 = wx.BoxSizer(wx.HORIZONTAL)
        hboxtitle23.Add(buttonTestLinkRefresh, proportion=0)
        hboxtitle23.Add(buttonAddTestLink, proportion=0, flag=wx.LEFT, border=5)
        hboxtitle23.Add(buttonModifyTestLink, proportion=0, flag=wx.LEFT, border=5)

        vbox1 = wx.BoxSizer(wx.VERTICAL)
        vbox1.Add(hboxtitle1, proportion=0, flag=wx.EXPAND)
        vbox1.Add(hboxtitle12, proportion=1, flag=wx.EXPAND)
        vbox1.Add(hboxtitle13, proportion=0, flag=wx.EXPAND | wx.TOP | wx.BOTTOM, border=5)

        vbox2 = wx.BoxSizer(wx.VERTICAL)
        vbox2.Add(hboxtitle2, proportion=0, flag=wx.EXPAND)
        vbox2.Add(hboxtitle22, proportion=1, flag=wx.EXPAND)
        vbox2.Add(hboxtitle23, proportion=0, flag=wx.EXPAND | wx.TOP | wx.BOTTOM, border=5)

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(vbox1, proportion=1, flag=wx.EXPAND)
        hbox.Add(vbox2, proportion=1, flag=wx.EXPAND | wx.LEFT, border=20)

        self.vbox.Add(hbox, proportion=1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=20)
        self.bkg.SetSizer(self.vbox)
        return self.bkg

    def MakeToolPageApplyVirTualResource(self):
        pass

    def __RefreshNotice(self, position):
        pass

    def __AddNotice(self):
        pass

    def __ModifyNotice(self):
        pass

    def __RefreshTestLink(self, param):
        pass

    def __AddTestLink(self):
        pass

    def __ModifyTestLink(self):
        pass

    def __ClickLinkRedmine(self):
        pass

    def __CameraInfoWindow(self):
        pass

    def __ApplyResourceListMenu(self, choice):
        choiceMap = copy.deepcopy(choice)
        theText000 = wx.StaticText(self.bkg, -1, u"测试床", style=wx.ALIGN_RIGHT)
        theComboxTestBed = wx.ComboBox(self.bkg, -1, value=self.Env_TestBed_List[0], choices=choiceMap[u"测试床"],
                                       style=wx.CB_DROPDOWN)
        self.allApplyComboxList.append(theComboxTestBed)

        theText001 = wx.StaticText(self.bkg, -1, u"产品组", style=wx.ALIGN_RIGHT)
        theComboxOrg1 = wx.ComboBox(self.bkg, -1, value="", choices=choiceMap[u"产品组"], style=wx.CB_DROPDOWN)
        self.allApplyComboxList.append(theComboxOrg1)

        theText002 = wx.StaticText(self.bkg, -1, u"组织", style=wx.ALIGN_RIGHT)
        theComboxOrg2 = wx.ComboBox(self.bkg, -1, value="", choices=choiceMap[u"组织"], style=wx.CB_DROPDOWN)
        self.allApplyComboxList.append(theComboxOrg2)

        theText003 = wx.StaticText(self.bkg, -1, u"用途", style=wx.ALIGN_RIGHT)
        theComboxUsage = wx.ComboBox(self.bkg, -1, value="", choices=choiceMap[u"用途"], style=wx.CB_DROPDOWN)
        self.allApplyComboxList.append(theComboxUsage)

        hbox000 = wx.BoxSizer(wx.HORIZONTAL)
        hbox000.Add(theText000, proportion=1, flag=wx.RIGHT | wx.TOP, border=6)
        hbox000.Add(theComboxTestBed, proportion=3, flag=wx.RIGHT | wx.TOP, border=3)

        hbox001 = wx.BoxSizer(wx.HORIZONTAL)
        hbox001.Add(theText001, proportion=1, flag=wx.RIGHT | wx.TOP, border=6)
        hbox001.Add(theComboxOrg1, proportion=3, flag=wx.RIGHT | wx.TOP, border=3)

        hbox002 = wx.BoxSizer(wx.HORIZONTAL)
        hbox002.Add(theText002, proportion=1, flag=wx.RIGHT | wx.TOP, border=6)
        hbox002.Add(theComboxOrg2, proportion=3, flag=wx.RIGHT | wx.TOP, border=3)

        hbox003 = wx.BoxSizer(wx.HORIZONTAL)
        hbox003.Add(theText003, proportion=1, flag=wx.RIGHT | wx.TOP, border=6)
        hbox003.Add(theComboxUsage, proportion=3, flag=wx.RIGHT | wx.TOP, border=3)

        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(hbox000, proportion=0, flag=wx.EXPAND)
        vbox.Add(hbox001, proportion=0, flag=wx.EXPAND)
        vbox.Add(hbox002, proportion=0, flag=wx.EXPAND)
        vbox.Add(hbox003, proportion=0, flag=wx.EXPAND)

        del choiceMap[u"产品组"]
        del choiceMap[u"组织"]
        del choiceMap[u"用途"]
        del choiceMap[u"测试床"]

        for key in choiceMap:
            if u"告警输入" in key:
                continue
            theText = wx.StaticText(self.bkg, -1, key, style=wx.RIGHT)
            theCombox = wx.ComboBox(self.bkg, -1, value="", choices=choiceMap[key], style=wx.CB_DROPDOWN)
            self.allApplyComboxList.append(theCombox)
            hbox = wx.BoxSizer(wx.HORIZONTAL)
            hbox.Add(theText, proportion=1, flag=wx.RIGHT | wx.TOP, border=6)
            hbox.Add(theCombox, proportion=3, flag=wx.RIGHT | wx.TOP, border=3)
            vbox.Add(hbox, proportion=0, flag=wx.EXPAND)

        alarmInAttributeMap = {}
        for aName in self.attributeNameAndNodeDecMap:
            if u"告警输入" not in aName:
                continue
            alarmInAttributeMap[aName] = self.attributeNameAndNodeDecMap[aName]
            alarmInAttributeList = sorted(alarmInAttributeMap.items(), key=lambda e: e[0])
            for attr in alarmInAttributeList:
                theText = wx.StaticText(self.bkg, -1, attr[0], style=wx.RIGHT)
                for i in range(len(attr[1])):
                    if u"可控开关" in attr[1][i]:
                        del attr[1][i]
                theCombox = wx.ComboBox(self.bkg, -1, value="", choices=attr[1], style=wx.CB_DROPDOWN)
                self.allApplyComboxList.append(theCombox)
                hbox = wx.BoxSizer(wx.HORIZONTAL)
                hbox.Add(theText, proportion=1, flag=wx.RIGHT | wx.TOP, border=6)
                hbox.Add(theCombox, proportion=3, flag=wx.RIGHT | wx.TOP, border=3)
                vbox.Add(hbox, proportion=0, flag=wx.EXPAND)

        self.allApplyInputMap = {}
        theTextKeyWords = wx.StaticText(self.bkg, -1, u"关键词（例:a|b|c）", style=wx.ALIGN_RIGHT)
        self.theinputkeywords = wx.TextCtrl(self.bkg)
        hboxkeywords = wx.BoxSizer(wx.HORIZONTAL)
        hboxkeywords.Add(theTextKeyWords, proportion=1, flag=wx.RIGHT | wx.TOP, border=6)
        hboxkeywords.Add(self.theinputkeywords, proportion=3, flag=wx.RIGHT | wx.TOP, border=3)
        vbox.Add(hboxkeywords, proportion=0, flag=wx.EXPAND)

        return vbox

    def __SetAttributeInputNull(self):
        pass

    def __EnableLockAndUnlockButton(self, param):
        pass

    def __applyDeviceListByAttribute(self, event):
        # for combox in self.allApplyComboxList:
        #     logger.info(combox.GetValue())
        data = self.TSLConnect.TSL_Get_Camara_List_By_Attribute("")
        self.AllDeviceListForm.renewForm(data)

    def __CreateFilterWindow(self):
        pass

    def __setServerMenu(self, evt, flag):
        pass

    def __LockSelectDeviceList(self):
        pass

    def __unLockSelectDeviceList(self):
        pass

    def __GetMyDeviceList(self):
        pass

    def __unLockSelectDeviceListWo(self):
        pass

    def __updateDevice(self):
        pass

    def __updateDeviceByBedNameWindow(self):
        pass

    def __deletePlan_update(self):
        pass

    def __restoreDevice(self):
        pass

    def __SFTPEnable(self):
        pass

    def __SSHEnable(self):
        pass

    def __SetNTPTime(self):
        pass

    def __collectLLTDataDevice(self):
        pass

    def __deleteLLTDataDevice(self):
        pass

    def __sendCreateBaseTOPOInfo(self):
        pass

    def __addCamera(self):
        pass

    def __deleteCamera(self):
        pass

    def __ModifyCamera(self):
        pass

    def __ModifyCameraIP(self):
        pass

    def __exportServer(self, evt, flag):
        pass

    def __sendIPCMailWindow(self):
        pass

    def __configQQLDB(self):
        pass

    def __unConfigQQLDB(self):
        pass

    def __saveUpdateFile(self):
        pass

    def __SDCardFormat(self):
        pass

    def __refreshIPCVersion(self):
        pass

    def __refreshIPCNetWork(self):
        pass

    def __refreshIPCNetWorkParameter(self):
        pass

    def __refreshIPCSDCard(self):
        pass

    def __addMoreIPC(self):
        pass

    def __ManualReleaseIPC(self):
        pass


class DataListViewForm():
    def __init__(self, parent, menuNameList):
        self.dvc = dv.DataViewCtrl(parent, id=-1,
                                   style=wx.BORDER_THEME | dv.DV_ROW_LINES | dv.DV_HORIZ_RULES | dv.DV_VERT_RULES | dv.DV_MULTIPLE)
        self.menuNameList = menuNameList
        for i in range(len(self.menuNameList)):
            if u"厂商" in self.menuNameList[i]:
                theWidth = 60
            elif u"型号" in self.menuNameList[i]:
                theWidth = 60
            elif u"软件版本号" in self.menuNameList[i]:
                theWidth = 60
            elif u"软件版本时间" in self.menuNameList[i]:
                theWidth = 60
            elif u"设备IP" in self.menuNameList[i]:
                theWidth = 60
            elif u"网络状态" in self.menuNameList[i]:
                theWidth = 60
            elif u"LCBB设备" in self.menuNameList[i]:
                theWidth = 60
            elif u"当前所属测试床" in self.menuNameList[i]:
                theWidth = 60
            elif u"当前使用人" in self.menuNameList[i]:
                theWidth = 60
            elif u"使用人IP" in self.menuNameList[i]:
                theWidth = 60
            elif u"开始使用时间" in self.menuNameList[i]:
                theWidth = 60
            elif u"可用时长" in self.menuNameList[i]:
                theWidth = 60
            elif u"一周利用率" in self.menuNameList[i]:
                theWidth = 60
            elif u"SD容量" in self.menuNameList[i]:
                theWidth = 60
            elif u"SN号" in self.menuNameList[i]:
                theWidth = 60
            elif u"安装位置" in self.menuNameList[i]:
                theWidth = 60
            elif u"部门" in self.menuNameList[i]:
                theWidth = 60
            elif u"组织" in self.menuNameList[i]:
                theWidth = 60
            elif u"产品类型" in self.menuNameList[i]:
                theWidth = 60
            elif u"设备挂账人" in self.menuNameList[i]:
                theWidth = 60
            elif u"备注一" in self.menuNameList[i]:
                theWidth = 60
            elif u"备注二" in self.menuNameList[i]:
                theWidth = 60
            elif u"升级计划" in self.menuNameList[i]:
                theWidth = 60
            else:
                theWidth = 60
            self.dvc.AppendTextColumn(self.menuNameList[i], i + 1, width=theWidth, mode=dv.DATAVIEW_CELL_EDITABLE)
        # 使能-排序和移动列
        c0 = self.dvc.PrependTextColumn("No.", 0, width=40)  # 首列
        c0.Alignment = wx.ALIGN_CENTER
        c0.Renderer.Alignment = wx.ALIGN_CENTER
        c0.MinWidth = 40
        c0.Reorderable = False  # 首列不能移动
        for c in self.dvc.Columns:
            c.Sortable = True
            c.Reorderable = True
            c.Resizable = True
        self.model = DeviceListModel([])
        self.dvc.AssociateModel(self.model)

    def renewForm(self, dataList=None):
        self.model = DeviceListModel(dataList)
        sort_col = self.dvc.GetSortingColumn()
        if sort_col is not None:
            sort_col.UnsetAsSortKey()
        self.dvc.AssociateModel(self.model)


class DeviceListModel(dv.DataViewIndexListModel):
    def __init__(self, data):
        dv.DataViewIndexListModel.__init__(self, len(data))
        self.data = data

    def GetColumnType(self, col):
        return "string"

    def GetValueByRow(self, row, col):
        if col == 0:
            return row + 1
        return self.data[row][col - 1]

    def SetValueByRow(self, value, row, col):
        # self.log.write("SetValue:(%d,%d) %s\n" % (row, col, value))
        self.data[row][col - 1] = value

    def GetColumnCount(self):
        return len(self.data[0])

    def GetCount(self):
        return len(self.data)

    def GetAttrByRow(self, row, col, attr):
        if col in range(100):
            if self.data[row][col - 1] in [u"正常", u"空闲可用"]:
                attr.SetColour((0, 176, 80))
            elif self.data[row][col - 1] in [u"网络异常", u"SSH异常", u"设备信息更新失败", u"程序未启动", u"产生异常"]:
                attr.SetColour("Red")
                attr.SetBold(True)
            elif self.data[row][col - 1] in [u"正在维护", u"使用中"]:
                attr.SetColour((237, 125, 49))
                attr.SetBold(True)
            elif u"(A)" in self.data[row][col - 1]:
                attr.SetColour((255, 0, 0))
            elif u"(B)" in self.data[row][col - 1]:
                attr.SetColour((0, 128, 0))
            elif u"(C)" in self.data[row][col - 1]:
                attr.SetColour((0, 0, 255))
            elif u"(D)" in self.data[row][col - 1]:
                attr.SetColour((255, 128, 0))
            elif u"(E)" in self.data[row][col - 1]:
                attr.SetColour((0, 128, 255))
            elif u"(F)" in self.data[row][col - 1]:
                attr.SetColour((128, 0, 0))
            elif u"(G)" in self.data[row][col - 1]:
                attr.SetColour((0, 128, 192))
            elif u"(H)" in self.data[row][col - 1]:
                attr.SetColour((128, 128, 192))
            elif u"(I)" in self.data[row][col - 1]:
                attr.SetColour((128, 64, 64))
            elif u"(J)" in self.data[row][col - 1]:
                attr.SetColour((255, 255, 128))
            elif u"(K)" in self.data[row][col - 1]:
                attr.SetColour((0, 0, 255))
            elif u"(L)" in self.data[row][col - 1]:
                attr.SetColour((0, 255, 0))
            elif u"(M)" in self.data[row][col - 1]:
                attr.SetColour((128, 128, 0))
            elif u"(N)" in self.data[row][col - 1]:
                attr.SetColour((64, 0, 0))
            elif u"(O)" in self.data[row][col - 1]:
                attr.SetColour((255, 0, 128))
            if re.search(re_expressions.IP_ADDRESS, self.data[row][col - 1]) != None:
                attr.SetBold(True)
            return True
        return False

    def Compare(self, item1, item2, col, ascending):
        if not ascending:
            item2, item1 = item1, item2
        row1 = self.GetItem(item1)
        row2 = self.GetItem(item2)
        if col == 0:
            return cmp(int(row1 + 1), int(row2 + 1))
        else:
            return cmp(self.data[row1][col - 1], self.data[row2][col - 1])

    def DeleteRows(self, rows):
        rows = list(rows)
        rows.sort(reverse=True)

        for row in rows:
            del self.data[row]
            self.RowDeleted(row)

    def AddRow(self, value):
        self.data.append(value)
        self.RowAppended()


if __name__ == '__main__':
    app = wx.App()
    Frame = LoginFrame()
    app.MainLoop()
